home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWResour / Include / FWResAcc.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  6.0 KB  |  207 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:        FWResAcc.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWRESACC_H
  11. #define FWRESACC_H
  12.  
  13. #ifndef FWSTDDEF_H
  14. #include "FWStdDef.h"
  15. #endif
  16.  
  17. #ifndef FWPRVRAC_H
  18. #include "FWPrvRAc.h"
  19. #endif
  20.  
  21. #ifndef FWEXCDEF_H
  22. #include "FWExcDef.h"
  23. #endif
  24.  
  25. #ifndef FWRESFIL_H
  26. #include "FWResFil.h"
  27. #endif
  28.  
  29. #if defined(FW_BUILD_WIN) && !defined(__WINDOWS_H)
  30. #include <windows.h>
  31. #endif
  32.  
  33. #if defined(FW_BUILD_MAC) && !defined(__TYPES__)
  34. #include <Types.h>
  35. #endif
  36.  
  37. #if FW_LIB_EXPORT_PRAGMAS
  38. #pragma lib_export on
  39. #endif
  40.  
  41. //========================================================================================
  42. // CLASS FW_CResource
  43. //========================================================================================
  44.  
  45. class FW_CLASS_ATTR FW_CResource FW_AUTO_DESTRUCT_OBJECT
  46. {
  47. public:
  48.  
  49.     ~ FW_CResource();
  50.         // Decrements the reference count.
  51.         // Delete the resource access ref if count goes to zero.
  52.  
  53.     FW_CResource(const FW_CResourceFile &file,
  54.                        FW_ResourceId resourceId,
  55.                        FW_ResourceType resourceType);
  56.         // Creates a new FW_CPrivResourceRep attached to the given resource.
  57.  
  58.     FW_CResource(const FW_CResource& other);
  59.         // Copy constructor.
  60.  
  61.     FW_CResource& operator=(const FW_CResource& other);
  62.         // Assignment operator.
  63.                  
  64.     unsigned long GetSize() const;
  65.         // Return the size of this resource in bytes.
  66.                            
  67.     void* GetData();
  68.         // Low level method. Clients should generally use FW_CAcquireResourceData objects.
  69.         // Lock the resource and return a pointer to the data.
  70.         // Client assumes responsiblity to call ReleaseData.
  71.         
  72.     void ReleaseData();
  73.         // Low level method. Clients should generally use FW_CAcquireResourceData objects.
  74.         // Unlock the resource.
  75.  
  76.     FW_ResourceHandle GetResourceHandle() const;
  77.         // Low level method. Clients should generally use FW_CAcquireResourceData objects.
  78.         // Return the platform (native) handle.
  79.         // This method should be used with caution, since it reveals platform specifics,
  80.         // and allows violation of internal lock counts, etc.
  81.     
  82. private:
  83.  
  84.     FW_PPrivResourceAccess fPrivResourceAccess;
  85. };
  86.  
  87. //----------------------------------------------------------------------------------------
  88. // FW_CResource::operator= 
  89. //----------------------------------------------------------------------------------------
  90.  
  91. inline FW_CResource& FW_CResource::operator=(const FW_CResource& other)
  92. {
  93.     fPrivResourceAccess = other.fPrivResourceAccess;
  94.     return *this;
  95. }
  96.                  
  97. //----------------------------------------------------------------------------------------
  98. // FW_CResource::GetSize
  99. //----------------------------------------------------------------------------------------
  100.  
  101. inline unsigned long FW_CResource::GetSize() const
  102. {
  103.     return fPrivResourceAccess->GetSize();
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. // FW_CResource::GetData
  108. //----------------------------------------------------------------------------------------
  109.  
  110. inline void* FW_CResource::GetData()
  111. {
  112.     return fPrivResourceAccess->GetData();
  113. }
  114.  
  115. //----------------------------------------------------------------------------------------
  116. // FW_CResource::ReleaseData
  117. //----------------------------------------------------------------------------------------
  118.  
  119. inline void FW_CResource::ReleaseData()
  120. {
  121.     fPrivResourceAccess->ReleaseData();
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // FW_CResource::GetResourceHandle
  126. //----------------------------------------------------------------------------------------
  127.  
  128. inline FW_ResourceHandle FW_CResource::GetResourceHandle() const
  129. {
  130.     return fPrivResourceAccess->GetResourceHandle();
  131. }
  132.  
  133.  
  134. //========================================================================================
  135. // CLASS FW_CAcquireResourceData
  136. //========================================================================================
  137.  
  138. class FW_CLASS_ATTR FW_CAcquireResourceData FW_AUTO_DESTRUCT_OBJECT
  139. {
  140.  
  141. public:
  142.  
  143.     FW_CAcquireResourceData(FW_CResource resource);
  144.         // Acquires the data using resource->GetData().
  145.         
  146.     ~ FW_CAcquireResourceData();
  147.         // Releases the data using resource->ReleaseData().
  148.         
  149.     void *GetData() const;
  150.         // Returns a void* pointer to the data.
  151.         
  152.     unsigned long GetSize() const;
  153.         // Returns the size of the resource, in bytes.
  154.     
  155. private:
  156.  
  157.     FW_CResource fResource;
  158.         // The resource.
  159.         
  160.     void* fData;
  161.         // The acquired data.
  162. };
  163.  
  164. //----------------------------------------------------------------------------------------
  165. // FW_CAcquireResourceData::GetData
  166. //----------------------------------------------------------------------------------------
  167.  
  168. inline void* FW_CAcquireResourceData::GetData() const
  169. {
  170.     return fData;
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. // FW_CAcquireResourceData::GetSize
  175. //----------------------------------------------------------------------------------------
  176.  
  177. inline unsigned long FW_CAcquireResourceData::GetSize() const
  178. {
  179.     return fResource.GetSize();
  180. }
  181.  
  182. //========================================================================================
  183. //    Global Utility Functions
  184. //========================================================================================
  185.  
  186. // These functions will probably be moved into the Strings component.
  187. // To do so, we will make Strings be dependent on the Streams component,
  188. // and then provide "load string from sink" functions.
  189.  
  190. void FW_FUNC_ATTR FW_LoadStringByPosition(FW_CResourceFile &file,
  191.                                           FW_ResourceId resourceId,
  192.                                           FW_ResourceType resourceType,
  193.                                           unsigned short position,
  194.                                           FW_CString &string);
  195.                     
  196. void FW_FUNC_ATTR FW_LoadStringByID(FW_CResourceFile &file,
  197.                                     FW_ResourceId resourceId,
  198.                                     FW_ResourceType resourceType,
  199.                                     unsigned long id,
  200.                                     FW_CString &string);
  201.  
  202. #if FW_LIB_EXPORT_PRAGMAS
  203. #pragma lib_export off
  204. #endif
  205.                     
  206. #endif
  207.